home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
General
/
DR1.#1 PPC C⁄C++ ƒ
/
C++ Runtime ƒ
/
runtime.s
< prev
next >
Wrap
Text File
|
1994-02-04
|
10KB
|
366 lines
# MWRuntime.s - Runtime Support routines for Metrowerks C++ for PowerPC
#
# Copyright © 1993 metrowerks inc. All Rights Reserved.
#
#
# Assembler Equates
#
.set r0,0; .set SP,1; .set RTOC,2; .set r3,3; .set r4,4; .set r5,5; .set r6,6; .set r7,7
.set r8,8; .set r9,9; .set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14; .set r15,15
.set r16,16; .set r17,17; .set r18,18; .set r19,19; .set r20,20; .set r21,21; .set r22,22; .set r23,23
.set r24,24; .set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29; .set r30,30; .set r31,31
.set fp0,0; .set fp1,1; .set fp2,2; .set fp3,3; .set fp4,4; .set fp5,5; .set fp6,6; .set fp7,7
.set fp8,8; .set fp9,9; .set fp10,10; .set fp11,11; .set fp12,12; .set fp13,13; .set fp14,14; .set fp15,15
.set fp16,16; .set fp17,17; .set fp18,18; .set fp19,19; .set fp20,20; .set fp21,21; .set fp22,22; .set fp23,23
.set fp24,24; .set fp25,25; .set fp26,26; .set fp27,27; .set fp28,28; .set fp29,29; .set fp30,30; .set fp31,31
.set cr0,0; .set cr1,1; .set cr2,2; .set cr3,3; .set cr4,4; .set cr5,5; .set cr6,6; .set cr7,7
.set MQ,0; .set XER,1; .set FROM_RTCU,4; .set FROM_RTCL,5; .set FROM_DEC,6; .set LR,8; .set CTR,9; .set TID,17
.set DSISR,18; .set DAR,19; .set TO_RTCU,20; .set TO_RTCL,21; .set TO_DEC,22; .set SDR_0,24; .set SDR_1,25; .set SRR_0,26
.set SRR_1,27
.set BO_dCTR_NZERO_AND_NOT,0; .set BO_dCTR_NZERO_AND_NOT_1,1; .set BO_dCTR_ZERO_AND_NOT,2; .set BO_dCTR_ZERO_AND_NOT_1,3
.set BO_IF_NOT,4; .set BO_IF_NOT_1,5; .set BO_IF_NOT_2,6; .set BO_IF_NOT_3,7
.set BO_dCTR_NZERO_AND,8; .set BO_dCTR_NZERO_AND_1,9; .set BO_dCTR_ZERO_AND,10; .set BO_dCTR_ZERO_AND_1,11
.set BO_IF,12; .set BO_IF_1,13; .set BO_IF_2,14; .set BO_IF_3,15
.set BO_dCTR_NZERO,16; .set BO_dCTR_NZERO_1,17; .set BO_dCTR_ZERO,18; .set BO_dCTR_ZERO_1,19
.set BO_ALWAYS,20; .set BO_ALWAYS_1,21; .set BO_ALWAYS_2,22; .set BO_ALWAYS_3,23
.set BO_dCTR_NZERO_8,24; .set BO_dCTR_NZERO_9,25; .set BO_dCTR_ZERO_8,26; .set BO_dCTR_ZERO_9,27
.set BO_ALWAYS_8,28; .set BO_ALWAYS_9,29; .set BO_ALWAYS_10,30; .set BO_ALWAYS_11,31
.set CR0_LT,0; .set CR0_GT,1; .set CR0_EQ,2; .set CR0_SO,3
.set CR1_FX,4; .set CR1_FEX,5; .set CR1_VX,6; .set CR1_OX,7
.set CR2_LT,8; .set CR2_GT,9; .set CR2_EQ,10; .set CR2_SO,11
.set CR3_LT,12; .set CR3_GT,13; .set CR3_EQ,14; .set CR3_SO,15
.set CR4_LT,16; .set CR4_GT,17; .set CR4_EQ,18; .set CR4_SO,19
.set CR5_LT,20; .set CR5_GT,21; .set CR5_EQ,22; .set CR5_SO,23
.set CR6_LT,24; .set CR6_GT,25; .set CR6_EQ,26; .set CR6_SO,27
.set CR7_LT,28; .set CR7_GT,29; .set CR7_EQ,30; .set CR7_SO,31
#
# Private Data
#
.csect __constants{RO}
.long 0x43300000 # integer->floating conversion constant
.long 0x80000000
.long 0x43300000 # unsigned->floating conversion constant
.long 0x00000000
.long 0x00000000 # 0.0
.long 0x00000000
.long 0x41F00000 # 2**32
.long 0x00000000
.long 0x41E00000 # 2**31
.long 0x00000000
.csect __argv{RW}
.long 0
#
# TOC pointers
#
.toc
T.__constants:
.tc __constants{TC}, __constants{RO}
# __cvt_int2single - convert 32-bit integer to floating-point single
#
# Convert the 32-bit integer in R3 to a floating-point single and return
# the result in F1.
#
.csect .__cvt_int2single{PR}
.globl .__cvt_int2single{PR}
lwz r4,T.__constants(RTOC)
xoris r0,r3,0x8000
lfd fp0,0(r4) # fp0 = integer->floating conversion constant
stw r0,-4(SP)
lis r0,0x4330
stw r0,-8(SP)
lfd fp1,-8(SP)
fsubs fp1,fp1,fp0
blr
# __cvt_int2double - convert 32-bit integer to floating-point double
#
# Convert the 32-bit integer in R3 to a floating-point double and return
# the result in F1.
#
.csect .__cvt_int2double{PR}
.globl .__cvt_int2double{PR}
lwz r4,T.__constants(RTOC)
xoris r0,r3,0x8000
lfd fp0,0(r4) # fp0 = integer->floating conversion constant
stw r0,-4(SP)
lis r0,0x4330
stw r0,-8(SP)
lfd fp1,-8(SP)
fsub fp1,fp1,fp0
blr
# __cvt_uns2single - convert 32-bit unsigned to floating-point single
#
# Convert the 32-bit integer in R3 to a floating-point single and return
# the result in F1.
#
.csect .__cvt_uns2single{PR}
.globl .__cvt_uns2single{PR}
lwz r4,T.__constants(RTOC)
stw r3,-4(SP)
lfd fp0,8(r4) # fp0 = unsigned->floating conversion constant
lis r0,0x4330
stw r0,-8(SP)
lfd fp1,-8(SP)
fsubs fp1,fp1,fp0
blr
# __cvt_uns2double - convert 32-bit unsigned to floating-point double
#
# Convert the 32-bit integer in R3 to a floating-point single and return
# the result in F1.
#
.csect .__cvt_uns2double{PR}
.globl .__cvt_uns2double{PR}
lwz r4,T.__constants(RTOC)
stw r3,-4(SP)
lfd fp0,8(r4) # fp0 = unsigned->floating conversion constant
lis r0,0x4330
stw r0,-8(SP)
lfd fp1,-8(SP)
fsub fp1,fp1,fp0
blr
# __cvt_fp2unsigned - convert floating-point to 32-bit unsigned integer
#
# Convert the floating-point value in F1 to a 32-bit unsigned integer
# and return the result in R3.
#
# This routine is copied from the Motorola PowerPC 602 Users Manual, pg. F-1.
#
.globl .__cvt_fp2unsigned{PR}
.csect .__cvt_fp2unsigned{PR}
lwz r4,T.__constants(RTOC)
li r3,0 # r3 = 0
lfd fp0,16(r4) # fp0 = 0.0
lfd fp3,24(r4) # fp3 = 2**32
lfd fp4,32(r4) # fp4 = 2**31
fcmpu cr0,fp1,fp0 # cr0 = compare(fp1,0.0)
fcmpu cr6,fp1,fp3 # cr6 = compare(fp1,2**32)
bltlr cr0 # return 0x00000000 if input was < 0.0
addi r3,r3,-1
bgelr cr6 # return 0xFFFFFFFF if input was >= 2**32
fcmpu cr7,fp1,fp4 # cr7 = compare(fp1,2**31)
fmr fp2,fp1
blt cr7,$+8 # use fp1 if < 2**31
fsub fp2,fp1,fp4 # subtract 2**31
fctiwz fp2,fp2 # convert float to 8-byte integer
stfd fp2,-8(SP) # store 8-byte integer
lwz r3,-4(SP) # load 4-byte integer
bltlr cr7
addis r3,r3,-32768 # add 2**31 if input was >= 2**31
blr
# __ptr_glue - glue for function calls through pointers
#
# Call the function whose 2-word TVector address is in R12.
#
.csect .__ptr_glue{GL}
.globl .__ptr_glue{GL}
lwz r0,0(r12)
stw RTOC,20(SP)
mtctr r0
lwz RTOC,4(r12)
bctr
# _ptrgl - AIX & Lucid compatible version of __ptr_glue
#
# Call the function whose 3-word TVector address is in R11.
#
.csect ._ptrgl{GL}
.globl ._ptrgl{GL}
lwz r0,0(r11)
stw RTOC,20(SP)
mtctr r0
lwz RTOC,4(r11)
lwz r11,8(r11)
bctr
# __blockmove - move (unaligned) block of data
#
# Move the # bytes in R5 from the address in R4 to the address in R3.
# The # bytes is at least 128. We move the data in 32-byte chunks.
#
.csect .__blockmove{PR}
.globl .__blockmove{PR}
# save some nonvolatile registers that we need
stw r13,-4(SP)
stw r14,-8(SP)
stw r15,-12(SP)
# set XER = chunk size
li r7,32
mtxer r7
# set CTR = #chunks to move
rlwinm r8,r5,27,5,31
mtctr r8
# set R5 = remainder
rlwinm. r5,r5,0,27,31 # cr0(eq) = no remainder
# copy 32-byte chunks
li r6,0
loop: lswx r8,r6,r4
stswx r8,r6,r3
addi r6,r6,32
bdnz loop
beq exit # return if no remainder
# copy remainder
mtxer r5
lswx r8,r6,r4
stswx r8,r6,r3
# restore registers and return
exit: lwz r15,-12(SP)
lwz r14,-8(SP)
lwz r13,-4(SP)
blr
#
# __save_fpr_XX - save FPR's XX through 31
#
.csect .__save_fpr{PR}
.globl .__save_fpr{PR}
.globl .__save_fpr_14
.globl .__save_fpr_15
.globl .__save_fpr_16
.globl .__save_fpr_17
.globl .__save_fpr_18
.globl .__save_fpr_19
.globl .__save_fpr_20
.globl .__save_fpr_21
.globl .__save_fpr_22
.globl .__save_fpr_23
.globl .__save_fpr_24
.globl .__save_fpr_25
.globl .__save_fpr_26
.globl .__save_fpr_27
.globl .__save_fpr_28
.globl .__save_fpr_29
.globl .__save_fpr_30
.globl .__save_fpr_31
.__save_fpr_14:
stfd fp14,-144(SP)
.__save_fpr_15:
stfd fp15,-136(SP)
.__save_fpr_16:
stfd fp16,-128(SP)
.__save_fpr_17:
stfd fp17,-120(SP)
.__save_fpr_18:
stfd fp18,-112(SP)
.__save_fpr_19:
stfd fp19,-104(SP)
.__save_fpr_20:
stfd fp20,-96(SP)
.__save_fpr_21:
stfd fp21,-88(SP)
.__save_fpr_22:
stfd fp22,-80(SP)
.__save_fpr_23:
stfd fp23,-72(SP)
.__save_fpr_24:
stfd fp24,-64(SP)
.__save_fpr_25:
stfd fp25,-56(SP)
.__save_fpr_26:
stfd fp26,-48(SP)
.__save_fpr_27:
stfd fp27,-40(SP)
.__save_fpr_28:
stfd fp28,-32(SP)
.__save_fpr_29:
stfd fp29,-24(SP)
.__save_fpr_30:
stfd fp30,-16(SP)
.__save_fpr_31:
stfd fp31,-8(SP)
blr
#
# __restore_fpr_XX - restore FPR's XX through 31
#
.csect .__restore_fpr{PR}
.globl .__restore_fpr{PR}
.globl .__restore_fpr_14
.globl .__restore_fpr_15
.globl .__restore_fpr_16
.globl .__restore_fpr_17
.globl .__restore_fpr_18
.globl .__restore_fpr_19
.globl .__restore_fpr_20
.globl .__restore_fpr_21
.globl .__restore_fpr_22
.globl .__restore_fpr_23
.globl .__restore_fpr_24
.globl .__restore_fpr_25
.globl .__restore_fpr_26
.globl .__restore_fpr_27
.globl .__restore_fpr_28
.globl .__restore_fpr_29
.globl .__restore_fpr_30
.globl .__restore_fpr_31
.__restore_fpr_14:
lfd fp14,-144(SP)
.__restore_fpr_15:
lfd fp15,-136(SP)
.__restore_fpr_16:
lfd fp16,-128(SP)
.__restore_fpr_17:
lfd fp17,-120(SP)
.__restore_fpr_18:
lfd fp18,-112(SP)
.__restore_fpr_19:
lfd fp19,-104(SP)
.__restore_fpr_20:
lfd fp20,-96(SP)
.__restore_fpr_21:
lfd fp21,-88(SP)
.__restore_fpr_22:
lfd fp22,-80(SP)
.__restore_fpr_23:
lfd fp23,-72(SP)
.__restore_fpr_24:
lfd fp24,-64(SP)
.__restore_fpr_25:
lfd fp25,-56(SP)
.__restore_fpr_26:
lfd fp26,-48(SP)
.__restore_fpr_27:
lfd fp27,-40(SP)
.__restore_fpr_28:
lfd fp28,-32(SP)
.__restore_fpr_29:
lfd fp29,-24(SP)
.__restore_fpr_30:
lfd fp30,-16(SP)
.__restore_fpr_31:
lfd fp31,-8(SP)
blr